package com.anlogic.sdk.templates.core.processes;

import org.eclipse.cdt.core.templateengine.TemplateCore;
import org.eclipse.cdt.core.templateengine.process.ProcessArgument;
import org.eclipse.cdt.core.templateengine.process.ProcessFailureException;
import org.eclipse.cdt.core.templateengine.process.ProcessRunner;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IProgressMonitor;

public class SetMBSToolchain extends ProcessRunner {
	@Override
	public void process(TemplateCore template, ProcessArgument[] args, String processId, IProgressMonitor monitor) throws ProcessFailureException {
		String projectName = args[0].getSimpleValue();
		String toolchainType = args[1].getSimpleValue();
		String toolchainName = args[2].getSimpleValue();
		String toolchainPath = args[3].getSimpleValue();
		String buildToolsPath = args[4].getSimpleValue();
		
		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
		
		if (toolchainType.equals("ARM")) {
			org.eclipse.embedcdt.managedbuild.cross.arm.core.ToolchainConfiguration.setToolchain(project, toolchainName, toolchainPath, buildToolsPath);
		} else if (toolchainType.equals("RISC-V")) {
			org.eclipse.embedcdt.managedbuild.cross.riscv.core.ToolchainConfiguration.setToolchain(project, toolchainName, toolchainPath, buildToolsPath);
		}
	}
}
